# event listener
from direct.showbase import DirectObject
import EventDefine
# file access
from Cube.utility.PythonObjectFileAccess import ObjectLoadFromFile
from Cube.game import QObjectBase
# CMDID
from Body.Command import CMD_UP,CMD_DOWN,CMD_LEFT,CMD_RIGHT,CMD_BTN0,CMD_BTN1

#ConfigureFilePath = "configure"

class Controller(DirectObject.DirectObject, QObjectBase):
    def __init__(self):
        QObjectBase.__init__(self)
        self.ControllerEventSet()

    def ControllerEventSet(self):
        cmdSend = self.CmdSend
        self.accept(EventDefine.event_CONTROLLER_UP, cmdSend, [ (CMD_UP,1) ]) # up
        self.accept("%s-up"%(EventDefine.event_CONTROLLER_UP), cmdSend, [ (CMD_UP,0) ])
        self.accept(EventDefine.event_CONTROLLER_DOWN, cmdSend, [ (CMD_DOWN,1) ]) # down
        self.accept("%s-up"%(EventDefine.event_CONTROLLER_DOWN), cmdSend, [ (CMD_DOWN,0) ])
        self.accept(EventDefine.event_CONTROLLER_LEFT, cmdSend, [ (CMD_LEFT,1) ]) # left
        self.accept("%s-up"%(EventDefine.event_CONTROLLER_LEFT), cmdSend, [ (CMD_LEFT,0) ])
        self.accept(EventDefine.event_CONTROLLER_RIGHT, cmdSend, [ (CMD_RIGHT,1) ]) # right
        self.accept("%s-up"%(EventDefine.event_CONTROLLER_RIGHT), cmdSend, [ (CMD_RIGHT,0) ])
        self.accept(EventDefine.event_CONTROLLER_BTN0, cmdSend, [ (CMD_BTN0,1) ]) # btn0
        self.accept("%s-up"%(EventDefine.event_CONTROLLER_BTN0), cmdSend, [ (CMD_BTN0,0) ])
        self.accept(EventDefine.event_CONTROLLER_BTN1, cmdSend, [ (CMD_BTN1,1) ]) # btn1
        self.accept("%s-up"%(EventDefine.event_CONTROLLER_BTN1), cmdSend, [ (CMD_BTN1,0) ])

    def DoDestroy(self):
        self.ignoreAll()
